<template>
  <div class="sidebar">
    <el-menu
      class="sidebar-el-menu"
      :default-active="onRoutes"
      :collapse="collapse"
      background-color="#324157"
      text-color="#bfcbd9"
      active-text-color="#20a0ff"
      unique-opened
      router
    >
      <template v-for="item in items">
        <template v-if="item.subs">
          <el-submenu :index="item.index" :key="item.index">
            <template slot="title">
              <i :class="item.icon"></i>
              <span slot="title">{{ item.title }}</span>
            </template>
            <template v-for="subItem in item.subs">
              <el-submenu v-if="subItem.subs" :index="subItem.index" :key="subItem.index">
                <template slot="title">{{ subItem.title }}</template>
                <el-menu-item
                  v-for="(threeItem,i) in subItem.subs"
                  :key="i"
                  :index="threeItem.index"
                >{{ threeItem.title }}</el-menu-item>
              </el-submenu>
              <el-menu-item v-else :index="subItem.index" :key="subItem.index">{{ subItem.title }}</el-menu-item>
            </template>
          </el-submenu>
        </template>
        <template v-else>
          <el-menu-item :index="item.index" :key="item.index">
            <i :class="item.icon"></i>
            <span slot="title">{{ item.title }}</span>
          </el-menu-item>
        </template>
      </template>
    </el-menu>
  </div>
</template>

<script>
import bus from "../common/bus";
export default {
  data() {
    return {
      key: 0, //根据0和1去判断两身份
      collapse: false,
      items: [],
      list: []
    };
  },
  computed: {
    onRoutes() {
      return this.$route.path.replace("/", "");
    }
  },
  created() {
    // this.getLoca();
    this.check()
  },
  methods: {
    // getLoca() {
    //   this.list = JSON.parse(localStorage.list);
    //   console.log(this.list);
    //   var a = 0;
    //   for (let i = 0; i < this.list.length; i++) {
    //     if (this.list[i].children == 0) {
    //       this.items.push({
    //         icon: "el-icon-lx-cascades",
    //         index: this.list[i].url,
    //         title: this.list[i].menuName
    //       });
    //     } else {
    //       this.items.push({
    //         icon: "el-icon-lx-cascades",
    //         index: a++,
    //         title: this.list[i].menuName,
    //         subs: []
    //       });

    //       for (var j = 0; j < this.list[i].children.length; j++) {
    //         // console.log(this.items)
    //         this.items[i].subs.push({
    //           index: this.list[i].children[j].url,
    //           title: this.list[i].children[j].menuName
    //         });
    //       }
    //     }
    //   }
    //   console.log(this.items);
    // }
    check() {
      this.items = [
        {
          icon: "el-icon-lx-cascades",
          index: "ProcessDefinition",
          title: "流程定义[谁都可以查看]"
        },
        {
          icon: "el-icon-lx-cascades",
          index: "nodeExamine",
          title: "节点审批[张三不能看到]"
        },
        {
          icon: "el-icon-lx-cascades",
          index: "historicalProcess",
          title: "自己发布的历史流程[已经处理完的]"
        },
        {
          icon: "el-icon-lx-cascades",
          index: "selectFlowDispose",
          title: "查询自己的流程该谁处理了"
        },
        {
          icon: "el-icon-lx-cascades",
          index: "workFlow",
          title: "所有已完成流程[只有管理可以查看]"
        },
        // {
        //   icon: "el-icon-lx-cascades",
        //   index: "maintain",
        //   title: "设备维护"
        // },
        {
          icon: "el-icon-lx-cascades",
          index: "notWorkFlow",
          title: "所有未完成流程[只有管理可以查看"
        },
        {
          icon: "el-icon-lx-cascades",
          index: "device",
          title: "设备管理"
        },
        {
          icon: "el-icon-lx-cascades",
          index: "staff",
          title: "员工管理"
        },
        {
          icon: "el-icon-lx-cascades",
          index: "agentpayrule",
          title: "代理商收费规则"
        },
        {
          icon: "el-icon-lx-cascades",
          index: "discountrule",
          title: "折扣规则"
        },
        {
          icon: "el-icon-lx-cascades",
          index: "maintainpayrule",
          title: "维护费用"
        },
        {
          icon: "el-icon-lx-cascades",
          index: "devicemonitorhistory",
          title: "设备监控记录"
        },
        {
          icon: "el-icon-lx-cascades",
          index: "devicemonitorexception",
          title: "设备异常记录"
        },
        {
          icon: "el-icon-lx-cascades",
          index: "workcontent",
          title: "工作内容"
        },
        {
          icon: "el-icon-lx-cascades",
          index: "finance",
          title: "财务管理"
        },
        {
          icon: "el-icon-lx-cascades",
          index: "agent",
          title: "代理商管理"
        },
        {
          icon: "el-icon-lx-cascades",
          index: "jurisdictionManage",
          title: "权限管理"
        },
        {
          icon: "el-icon-lx-cascades",
          index: "maintainManage",
          title: "维修人员管理"
        },
        {
          icon: "el-icon-lx-cascades",
          index: "userPermission",
          title: "userPermission"
        },
        {
          icon: "el-icon-lx-cascades",
          index: "adminPermission",
          title: "adminPermission"
        }
      ];
    }
  }
};
</script>

<style scoped>
.sidebar {
  display: block;
  position: absolute;
  left: 0;
  top: 70px;
  bottom: 0;
  overflow-y: scroll;
}
.sidebar::-webkit-scrollbar {
  width: 0;
}
.sidebar-el-menu:not(.el-menu--collapse) {
  width: 250px;
}
.sidebar > ul {
  height: 100%;
}
</style>
